from requests.packages.urllib3.exceptions import InsecureRequestWarning

# !usr/bin/env python
# -*- coding:utf-8 -*-

import requests
import json
import base64
import time
import os
import webbrowser
import re
import emoji
import ssl
import fileinput
import sys
import random
import threading
import pygame
import configparser
import tkinter.messagebox
from tkinter import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from PIL import Image
from io import BytesIO
import numpy as np
import sklearn
from  sklearn import cluster
import cv2
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

ssl._create_default_https_context = ssl._create_unverified_context


class QJ:
    quekouXzuobiaozhi = 0
    tuling_zhanghao = ""
    tuling_mima = ""
    miyun_apizhanghao = ""
    miyun_mima = ""

def kaishizhuce ():
    """
    try:
        print("设置浏览器标识(User-Agent):" + ua_list_suiji)
        options = webdriver.ChromeOptions()
        # options.add_experimental_option("detach", True)
        options.add_argument('User-Agent=' + ua_list_suiji)
        driver = webdriver.Chrome(executable_path="Google Chrome/chromedriver.exe", chrome_options=options)
        # 打开注册网站
        driver.get("https://loyalty.shell.com.cn/wechat/aboutshell.action?source=wechat")
        time.sleep(1)
        # 点击注册按钮
        driver.find_element_by_class_name("reg").click()
        time.sleep(1)
        # 输入手机号
        # 这里还差获取接码平台手机号
        shoujihao = "12345678912"
        shoujihaodingwei = driver.find_element_by_id("phoneNum").send_keys(shoujihao)
        time.sleep(1)
        # 点击注册地
        driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
        # driver.find_element_by_class_name("van-field__right-icon").click()
        time.sleep(1)
        # 选择省份
        driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
        # driver.find_elements_by_class_name("van-cascader__option")[7].click()
        # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
        # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
        time.sleep(1)
        # 选择市
        driver.find_elements_by_class_name("van-cascader__option")[17].click()
        # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
        time.sleep(1)
        # 点击获取验证码按钮
        driver.find_element_by_class_name("van-field__button").click()
        time.sleep(1)
        # 下一步内容
        # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
        ##按照页面进行元素定位
        element = driver.find_element_by_class_name("verifybox")
        ##获取你的坐标{X,Y}
        location = element.location
        ##获取高度跟宽度
        size = element.size

        ##保存整个页面的截图
        png = driver.get_screenshot_as_png()


        ##使用PIL库在内存中打开图像
        im = Image.open(BytesIO(png))

        ##根据实际情况进行算法
        top = location['y']
        left = location['x']
        bottom = + size['height']
        right = + size['width']

        im = im.crop((left, top, right, bottom))
        ##截图
        im.save('截图.png')

    except Exception as error:
        print("报错信息:{0}".format(error))
    """
    if not os.path.exists('.\\shell_zhuceji_config.ini'):
        open('.\\shell_zhuceji_config.ini', "w")
        print("正在生成配置文件,生成后自动退出.退出后请先填写配置文件~")
    if not os.path.getsize('.\\shell_zhuceji_config.ini'):
        config = configparser.ConfigParser()
        config.read('.\\shell_zhuceji_config.ini')

        if config.has_section('米云设置') == False:
            config.add_section('米云设置')
            config.set('米云设置', '米云api账号', "")
            config.set('米云设置', '米云密码', "")

        if config.has_section('图灵设置') == False:
            config.add_section('图灵设置')
            config.set('图灵设置', '图灵账号', "")
            config.set('图灵设置', '图灵密码', "")
        o = open('.\\shell_zhuceji_config.ini', 'w')
        config.write(o)
        o.close()  # 不要忘记关闭
    else:
        config = configparser.ConfigParser()
        config.read('.\\shell_zhuceji_config.ini')

        QJ.miyun_apizhanghao = config.get('米云设置', '米云api账号')
        QJ.miyun_mima = config.get('米云设置', '米云密码')

        QJ.tuling_zhanghao = config.get('图灵设置', '图灵账号')
        QJ.tuling_mima = config.get('图灵设置', '图灵密码')

    if QJ.miyun_apizhanghao == "" or QJ.miyun_mima == "" or QJ.tuling_zhanghao == "" or QJ.tuling_mima == "":
        print("请填写配置文件~")
        exit()

    # -------------------------------------分割线


    chongfucishu_wenben = input("请输入获取次数：")
    chongfucishu = int(chongfucishu_wenben)

    if not os.path.exists("./手机号"):
        os.makedirs("./手机号")

    if not os.path.exists("./手机号/原先已注册.txt"):
        # print("创建预设文件 uid ...")
        print("正在生成原先已注册手机号文件~")
        open("./手机号/原先已注册.txt", "w")

    for jici in range(chongfucishu):
        dangqianshijian = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        baocunlujing = "./" + "手机号/" + dangqianshijian + ".txt"
        if not os.path.exists(baocunlujing):
            # print("创建预设文件 uid ...")
            print("正在生成注册完成手机号文件~")
            open(baocunlujing, "w")
        print("当前第"+ str(jici+1) + "个丨共"+ str(chongfucishu) + "个")
        miyundenglu = requests.get("http://api.miyun.pro/api/login?apiName=" + QJ.miyun_apizhanghao + "&password=" + QJ.miyun_mima,
                                   verify=False)
        miyundenglu_shuju = miyundenglu.text
        miyundenglu_shuju = json.loads(miyundenglu_shuju)
        miyun_token = (miyundenglu_shuju['token'])
        time.sleep(1)
        options = webdriver.ChromeOptions()
        driver = webdriver.Chrome(executable_path="Google Chrome/chromedriver.exe", chrome_options=options)
        driver.implicitly_wait(30)
        # 打开注册网站
        driver.get("https://loyalty.shell.com.cn/wechat/aboutshell.action?source=wechat")
        time.sleep(1)
        # 点击注册按钮
        driver.find_element_by_class_name("reg").click()
        time.sleep(1)
        # 获取手机号
        miyundeng_huoqushoujihao = requests.get(
            "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
        miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
        miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
        miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
        while miyun_shoujihao != "":
            print("获取的手机号:" + miyun_shoujihao)
            break
        else:
            miyundeng_huoqushoujihao = requests.get(
                "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
            miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
            miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
            miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
        # 输入手机号
        driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
        time.sleep(1)
        # 点击注册地
        driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
        # driver.find_element_by_class_name("van-field__right-icon").click()
        time.sleep(1)
        # 选择省份
        driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
        # driver.find_elements_by_class_name("van-cascader__option")[7].click()
        # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
        # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
        time.sleep(1)
        # 选择市
        driver.find_elements_by_class_name("van-cascader__option")[17].click()
        # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
        time.sleep(1)
        # 点击获取验证码按钮
        driver.find_element_by_class_name("van-field__button").click()
        time.sleep(1)
        # 下一步内容
        # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
        ##按照页面进行元素定位
        element = driver.find_element_by_class_name("verify-img-panel")
        ##获取你的坐标{X,Y}
        location = element.location
        ##获取高度跟宽度
        size = element.size

        ##保存整个页面的截图
        png = driver.get_screenshot_as_png()

        ##使用PIL库在内存中打开图像
        im = Image.open(BytesIO(png))

        ##根据实际情况进行算法
        left = location['x']
        top = location['y']
        right = location['x'] + size['width']
        bottom = location['y'] + size['height']

        im = im.crop((left, top, right, bottom))
        ##截图
        im.save('yanzhengma.png')
        driver.switch_to.default_content()
        time.sleep(1)
        jiemajisuan()
        time.sleep(1)

        huakuai = driver.find_element_by_class_name("verify-move-block")

        ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
        # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
        for x in get_track(QJ.quekouXzuobiaozhi - 25):
            ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
        time.sleep(1)
        ActionChains(driver).release().perform()

        time.sleep(1)
        yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
        while yanzhengmashifoucunzai == "向右滑动完成验证":
            element = driver.find_element_by_class_name("verify-img-panel")
            ##获取你的坐标{X,Y}
            location = element.location
            ##获取高度跟宽度
            size = element.size

            ##保存整个页面的截图
            png = driver.get_screenshot_as_png()

            ##使用PIL库在内存中打开图像
            im = Image.open(BytesIO(png))

            ##根据实际情况进行算法
            left = location['x']
            top = location['y']
            right = location['x'] + size['width']
            bottom = location['y'] + size['height']

            im = im.crop((left, top, right, bottom))
            ##截图
            im.save('yanzhengma.png')
            driver.switch_to.default_content()
            time.sleep(1)
            jiemajisuan()
            time.sleep(1)

            huakuai = driver.find_element_by_class_name("verify-move-block")

            ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
            # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
            for x in get_track(QJ.quekouXzuobiaozhi - 25):
                ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
            time.sleep(1)
            ActionChains(driver).release().perform()

            yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
            if yanzhengmashifoucunzai != "向右滑动完成验证":
                break
            time.sleep(3)

        shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
        while shoujihaoyizhuce == "此手机号已注册，请直接登录":
            baocunshoujihao1 = open("./手机号/原先已注册.txt", "a+")
            baocunshoujihao1.write(miyun_shoujihao + "\n")
            baocunshoujihao1.close()
            print(miyun_shoujihao + "------已注册------已保存")
            # 获取手机号
            miyundeng_huoqushoujihao = requests.get(
                "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
            miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
            miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
            miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
            while miyun_shoujihao != "":
                print("获取的手机号:" + miyun_shoujihao)
                break
            else:
                miyundeng_huoqushoujihao = requests.get(
                    "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
            # 清空手机号
            driver.find_element_by_id("phoneNum").clear()
            time.sleep(1)
            # 输入手机号
            driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
            time.sleep(1)
            """
            # 点击注册地
            driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
            # driver.find_element_by_class_name("van-field__right-icon").click()
            time.sleep(1)
            # 选择省份
            driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
            # driver.find_elements_by_class_name("van-cascader__option")[7].click()
            # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
            # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
            time.sleep(1)
            # 选择市
            driver.find_elements_by_class_name("van-cascader__option")[17].click()
            # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
            time.sleep(1)
            """
            # 点击获取验证码按钮
            driver.find_element_by_class_name("van-field__button").click()
            time.sleep(1)
            # 下一步内容
            # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
            ##按照页面进行元素定位
            element = driver.find_element_by_class_name("verify-img-panel")
            ##获取你的坐标{X,Y}
            location = element.location
            ##获取高度跟宽度
            size = element.size

            ##保存整个页面的截图
            png = driver.get_screenshot_as_png()

            ##使用PIL库在内存中打开图像
            im = Image.open(BytesIO(png))

            ##根据实际情况进行算法
            left = location['x']
            top = location['y']
            right = location['x'] + size['width']
            bottom = location['y'] + size['height']

            im = im.crop((left, top, right, bottom))
            ##截图
            im.save('yanzhengma.png')
            driver.switch_to.default_content()
            time.sleep(1)
            jiemajisuan()
            time.sleep(1)

            huakuai = driver.find_element_by_class_name("verify-move-block")

            ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
            # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
            for x in get_track(QJ.quekouXzuobiaozhi - 25):
                ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
            time.sleep(1)
            ActionChains(driver).release().perform()

            time.sleep(1)
            yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
            while yanzhengmashifoucunzai == "向右滑动完成验证":
                element = driver.find_element_by_class_name("verify-img-panel")
                ##获取你的坐标{X,Y}
                location = element.location
                ##获取高度跟宽度
                size = element.size

                ##保存整个页面的截图
                png = driver.get_screenshot_as_png()

                ##使用PIL库在内存中打开图像
                im = Image.open(BytesIO(png))

                ##根据实际情况进行算法
                left = location['x']
                top = location['y']
                right = location['x'] + size['width']
                bottom = location['y'] + size['height']

                im = im.crop((left, top, right, bottom))
                ##截图
                im.save('yanzhengma.png')
                driver.switch_to.default_content()
                time.sleep(1)
                jiemajisuan()
                time.sleep(1)

                huakuai = driver.find_element_by_class_name("verify-move-block")

                ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                for x in get_track(QJ.quekouXzuobiaozhi - 25):
                    ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                time.sleep(1)
                ActionChains(driver).release().perform()

                yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                if yanzhengmashifoucunzai != "向右滑动完成验证":
                    break
                time.sleep(3)

            shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
            if shoujihaoyizhuce != "此手机号已注册，请直接登录":
                break
            time.sleep(3)

        # 判断下一步是否可以点击
        # 获取验证码
        miyundeng_huoquyanzhengma = requests.get(
            "http://api.miyun.pro/api/get_message?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
            verify=False)
        miyundeng_huoquyanzhengma_shuju = miyundeng_huoquyanzhengma.text
        miyundeng_huoquyanzhengma_shuju = json.loads(miyundeng_huoquyanzhengma_shuju)
        miyun_yanzhengma = (miyundeng_huoquyanzhengma_shuju['code'])
        yzm = 0
        while miyun_yanzhengma == "":
            time.sleep(5)
            miyundeng_huoquyanzhengma = requests.get(
                "http://api.miyun.pro/api/get_message?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
                verify=False)
            miyundeng_huoquyanzhengma_shuju = miyundeng_huoquyanzhengma.text
            miyundeng_huoquyanzhengma_shuju = json.loads(miyundeng_huoquyanzhengma_shuju)
            miyun_yanzhengma = (miyundeng_huoquyanzhengma_shuju['code'])
            if miyun_yanzhengma != "":
                driver.find_element_by_id("validateCode").send_keys(miyun_yanzhengma)
                print("获取的验证码:" + miyun_yanzhengma)
                yzm = 0
                break
            else:
                yzm = yzm + 1
                print("正在获取" + str(yzm) + "次验证码,每5秒获取1次,共获取30次")
            if yzm == 30:
                # 拉黑
                miyun_lahei = requests.get(
                    "http://api.miyun.pro/api/add_blacklist?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
                    verify=False)
                miyun_lahei_shuju = miyun_lahei.text
                miyun_lahei_shuju = json.loads(miyun_lahei_shuju)
                miyun_lahei_fanhui = miyun_lahei_shuju['message']
                if miyun_lahei_fanhui == "ok":
                    print(miyun_shoujihao + "避免再次获取已拉黑")
                    miyun_shoujihao = ""
                    miyun_yanzhengma = ""
                driver.refresh()
                time.sleep(3)
                # 获取手机号
                miyundeng_huoqushoujihao = requests.get(
                    "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                while miyun_shoujihao != "":
                    print("获取的手机号:" + miyun_shoujihao)
                    break
                else:
                    miyundeng_huoqushoujihao = requests.get(
                        "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                    miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                    miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                    miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                # 输入手机号
                driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
                time.sleep(1)
                # 点击注册地
                driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
                # driver.find_element_by_class_name("van-field__right-icon").click()
                time.sleep(1)
                # 选择省份
                driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
                # driver.find_elements_by_class_name("van-cascader__option")[7].click()
                # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
                # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
                time.sleep(1)
                # 选择市
                driver.find_elements_by_class_name("van-cascader__option")[17].click()
                # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
                time.sleep(1)
                # 点击获取验证码按钮
                driver.find_element_by_class_name("van-field__button").click()
                time.sleep(1)
                # 下一步内容
                # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
                ##按照页面进行元素定位
                element = driver.find_element_by_class_name("verify-img-panel")
                ##获取你的坐标{X,Y}
                location = element.location
                ##获取高度跟宽度
                size = element.size

                ##保存整个页面的截图
                png = driver.get_screenshot_as_png()

                ##使用PIL库在内存中打开图像
                im = Image.open(BytesIO(png))

                ##根据实际情况进行算法
                left = location['x']
                top = location['y']
                right = location['x'] + size['width']
                bottom = location['y'] + size['height']

                im = im.crop((left, top, right, bottom))
                ##截图
                im.save('yanzhengma.png')
                driver.switch_to.default_content()
                time.sleep(1)
                jiemajisuan()
                time.sleep(1)

                huakuai = driver.find_element_by_class_name("verify-move-block")

                ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                for x in get_track(QJ.quekouXzuobiaozhi - 25):
                    ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                time.sleep(1)
                ActionChains(driver).release().perform()

                time.sleep(1)
                yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                while yanzhengmashifoucunzai == "向右滑动完成验证":
                    element = driver.find_element_by_class_name("verify-img-panel")
                    ##获取你的坐标{X,Y}
                    location = element.location
                    ##获取高度跟宽度
                    size = element.size

                    ##保存整个页面的截图
                    png = driver.get_screenshot_as_png()

                    ##使用PIL库在内存中打开图像
                    im = Image.open(BytesIO(png))

                    ##根据实际情况进行算法
                    left = location['x']
                    top = location['y']
                    right = location['x'] + size['width']
                    bottom = location['y'] + size['height']

                    im = im.crop((left, top, right, bottom))
                    ##截图
                    im.save('yanzhengma.png')
                    driver.switch_to.default_content()
                    time.sleep(1)
                    jiemajisuan()
                    time.sleep(1)

                    huakuai = driver.find_element_by_class_name("verify-move-block")

                    ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                    # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                    for x in get_track(QJ.quekouXzuobiaozhi - 25):
                        ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                    time.sleep(1)
                    ActionChains(driver).release().perform()

                    yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                    if yanzhengmashifoucunzai != "向右滑动完成验证":
                        break
                    time.sleep(3)

                shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
                while shoujihaoyizhuce == "此手机号已注册，请直接登录":
                    baocunshoujihao1 = open("./手机号/原先已注册.txt", "a+")
                    baocunshoujihao1.write(miyun_shoujihao + "\n")
                    baocunshoujihao1.close()
                    print(miyun_shoujihao + "------已注册------已保存")
                    # 获取手机号
                    miyundeng_huoqushoujihao = requests.get(
                        "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                    miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                    miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                    miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                    while miyun_shoujihao != "":
                        print("获取的手机号:" + miyun_shoujihao)
                        break
                    else:
                        miyundeng_huoqushoujihao = requests.get(
                            "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964",
                            verify=False)
                        miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                        miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                        miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                    # 清空手机号
                    driver.find_element_by_id("phoneNum").clear()
                    time.sleep(1)
                    # 输入手机号
                    driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
                    time.sleep(1)
                    """
                    # 点击注册地
                    driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
                    # driver.find_element_by_class_name("van-field__right-icon").click()
                    time.sleep(1)
                    # 选择省份
                    driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
                    # driver.find_elements_by_class_name("van-cascader__option")[7].click()
                    # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
                    # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
                    time.sleep(1)
                    # 选择市
                    driver.find_elements_by_class_name("van-cascader__option")[17].click()
                    # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
                    time.sleep(1)
                    """
                    # 点击获取验证码按钮
                    driver.find_element_by_class_name("van-field__button").click()
                    time.sleep(1)
                    # 下一步内容
                    # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
                    ##按照页面进行元素定位
                    element = driver.find_element_by_class_name("verify-img-panel")
                    ##获取你的坐标{X,Y}
                    location = element.location
                    ##获取高度跟宽度
                    size = element.size

                    ##保存整个页面的截图
                    png = driver.get_screenshot_as_png()

                    ##使用PIL库在内存中打开图像
                    im = Image.open(BytesIO(png))

                    ##根据实际情况进行算法
                    left = location['x']
                    top = location['y']
                    right = location['x'] + size['width']
                    bottom = location['y'] + size['height']

                    im = im.crop((left, top, right, bottom))
                    ##截图
                    im.save('yanzhengma.png')
                    driver.switch_to.default_content()
                    time.sleep(1)
                    jiemajisuan()
                    time.sleep(1)

                    huakuai = driver.find_element_by_class_name("verify-move-block")

                    ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                    # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                    for x in get_track(QJ.quekouXzuobiaozhi - 25):
                        ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                    time.sleep(1)
                    ActionChains(driver).release().perform()

                    time.sleep(1)
                    yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                    while yanzhengmashifoucunzai == "向右滑动完成验证":
                        element = driver.find_element_by_class_name("verify-img-panel")
                        ##获取你的坐标{X,Y}
                        location = element.location
                        ##获取高度跟宽度
                        size = element.size

                        ##保存整个页面的截图
                        png = driver.get_screenshot_as_png()

                        ##使用PIL库在内存中打开图像
                        im = Image.open(BytesIO(png))

                        ##根据实际情况进行算法
                        left = location['x']
                        top = location['y']
                        right = location['x'] + size['width']
                        bottom = location['y'] + size['height']

                        im = im.crop((left, top, right, bottom))
                        ##截图
                        im.save('yanzhengma.png')
                        driver.switch_to.default_content()
                        time.sleep(1)
                        jiemajisuan()
                        time.sleep(1)

                        huakuai = driver.find_element_by_class_name("verify-move-block")

                        ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                        # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                        for x in get_track(QJ.quekouXzuobiaozhi - 25):
                            ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                        time.sleep(1)
                        ActionChains(driver).release().perform()

                        yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                        if yanzhengmashifoucunzai != "向右滑动完成验证":
                            break
                        time.sleep(3)

                    shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
                    if shoujihaoyizhuce != "此手机号已注册，请直接登录":
                        break
                    time.sleep(3)

        time.sleep(3)
        driver.find_element_by_class_name("van-button--large").click()
        """
        xiayibuanniu = driver.find_element_by_class_name("van-button--large")
        panduanxiayibukefoudianji = xiayibuanniu.is_enabled()
        #如果不能点击下一步拉黑号码并重新申请号码
        while panduanxiayibukefoudianji == True:
            driver.find_element_by_class_name("van-button--large").click()
            break
        else:
            driver.refresh()
            miyun_shoujihao = ""
            miyun_yanzhengma = ""
            time.sleep(3)
            # 获取手机号
            miyundeng_huoqushoujihao = requests.get(
                "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
            miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
            miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
            miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
            while miyun_shoujihao != "":
                print("获取的手机号:" + miyun_shoujihao)
                break
            else:
                miyundeng_huoqushoujihao = requests.get(
                    "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
            # 输入手机号
            driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
            time.sleep(1)
            # 点击注册地
            driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
            # driver.find_element_by_class_name("van-field__right-icon").click()
            time.sleep(1)
            # 选择省份
            driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
            # driver.find_elements_by_class_name("van-cascader__option")[7].click()
            # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
            # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
            time.sleep(1)
            # 选择市
            driver.find_elements_by_class_name("van-cascader__option")[17].click()
            # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
            time.sleep(1)
            # 点击获取验证码按钮
            driver.find_element_by_class_name("van-field__button").click()
            time.sleep(1)
            # 下一步内容
            # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
            ##按照页面进行元素定位
            element = driver.find_element_by_class_name("verify-img-panel")
            ##获取你的坐标{X,Y}
            location = element.location
            ##获取高度跟宽度
            size = element.size

            ##保存整个页面的截图
            png = driver.get_screenshot_as_png()

            ##使用PIL库在内存中打开图像
            im = Image.open(BytesIO(png))

            ##根据实际情况进行算法
            left = location['x']
            top = location['y']
            right = location['x'] + size['width']
            bottom = location['y'] + size['height']

            im = im.crop((left, top, right, bottom))
            ##截图
            im.save('yanzhengma.png')
            driver.switch_to.default_content()
            time.sleep(1)
            jiemajisuan()
            time.sleep(1)

            huakuai = driver.find_element_by_class_name("verify-move-block")

            ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
            # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
            for x in get_track(QJ.quekouXzuobiaozhi - 25):
                ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
            time.sleep(1)
            ActionChains(driver).release().perform()

            time.sleep(1)
            yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
            while yanzhengmashifoucunzai == "向右滑动完成验证":
                element = driver.find_element_by_class_name("verify-img-panel")
                ##获取你的坐标{X,Y}
                location = element.location
                ##获取高度跟宽度
                size = element.size

                ##保存整个页面的截图
                png = driver.get_screenshot_as_png()

                ##使用PIL库在内存中打开图像
                im = Image.open(BytesIO(png))

                ##根据实际情况进行算法
                left = location['x']
                top = location['y']
                right = location['x'] + size['width']
                bottom = location['y'] + size['height']

                im = im.crop((left, top, right, bottom))
                ##截图
                im.save('yanzhengma.png')
                driver.switch_to.default_content()
                time.sleep(1)
                jiemajisuan()
                time.sleep(1)

                huakuai = driver.find_element_by_class_name("verify-move-block")

                ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                for x in get_track(QJ.quekouXzuobiaozhi - 25):
                    ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                time.sleep(1)
                ActionChains(driver).release().perform()

                yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                if yanzhengmashifoucunzai != "向右滑动完成验证":
                    break
                time.sleep(3)

            shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
            while shoujihaoyizhuce == "此手机号已注册，请直接登录":
                # 获取手机号
                miyundeng_huoqushoujihao = requests.get(
                    "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                while miyun_shoujihao != "":
                    print("获取的手机号:" + miyun_shoujihao)
                    break
                else:
                    miyundeng_huoqushoujihao = requests.get(
                        "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                    miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                    miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                    miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                # 输入手机号
                driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
                time.sleep(1)
                # 点击注册地
                driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
                # driver.find_element_by_class_name("van-field__right-icon").click()
                time.sleep(1)
                # 选择省份
                driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
                # driver.find_elements_by_class_name("van-cascader__option")[7].click()
                # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
                # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
                time.sleep(1)
                # 选择市
                driver.find_elements_by_class_name("van-cascader__option")[17].click()
                # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
                time.sleep(1)
                # 点击获取验证码按钮
                driver.find_element_by_class_name("van-field__button").click()
                time.sleep(1)
                # 下一步内容
                # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
                ##按照页面进行元素定位
                element = driver.find_element_by_class_name("verify-img-panel")
                ##获取你的坐标{X,Y}
                location = element.location
                ##获取高度跟宽度
                size = element.size

                ##保存整个页面的截图
                png = driver.get_screenshot_as_png()

                ##使用PIL库在内存中打开图像
                im = Image.open(BytesIO(png))

                ##根据实际情况进行算法
                left = location['x']
                top = location['y']
                right = location['x'] + size['width']
                bottom = location['y'] + size['height']

                im = im.crop((left, top, right, bottom))
                ##截图
                im.save('yanzhengma.png')
                driver.switch_to.default_content()
                time.sleep(1)
                jiemajisuan()
                time.sleep(1)

                huakuai = driver.find_element_by_class_name("verify-move-block")

                ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                for x in get_track(QJ.quekouXzuobiaozhi - 25):
                    ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                time.sleep(1)
                ActionChains(driver).release().perform()

                time.sleep(1)
                yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                while yanzhengmashifoucunzai == "向右滑动完成验证":
                    element = driver.find_element_by_class_name("verify-img-panel")
                    ##获取你的坐标{X,Y}
                    location = element.location
                    ##获取高度跟宽度
                    size = element.size

                    ##保存整个页面的截图
                    png = driver.get_screenshot_as_png()

                    ##使用PIL库在内存中打开图像
                    im = Image.open(BytesIO(png))

                    ##根据实际情况进行算法
                    left = location['x']
                    top = location['y']
                    right = location['x'] + size['width']
                    bottom = location['y'] + size['height']

                    im = im.crop((left, top, right, bottom))
                    ##截图
                    im.save('yanzhengma.png')
                    driver.switch_to.default_content()
                    time.sleep(1)
                    jiemajisuan()
                    time.sleep(1)

                    huakuai = driver.find_element_by_class_name("verify-move-block")

                    ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                    # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                    for x in get_track(QJ.quekouXzuobiaozhi - 25):
                        ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                    time.sleep(1)
                    ActionChains(driver).release().perform()

                    yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                    if yanzhengmashifoucunzai != "向右滑动完成验证":
                        break
                    time.sleep(3)

                shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
                if shoujihaoyizhuce != "此手机号已注册，请直接登录":
                    break
                time.sleep(3)

            # 判断下一步是否可以点击
            # 获取验证码
            miyundeng_huoquyanzhengma = requests.get(
                "http://api.miyun.pro/api/get_message?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
                verify=False)
            miyundeng_huoquyanzhengma_shuju = miyundeng_huoquyanzhengma.text
            miyundeng_huoquyanzhengma_shuju = json.loads(miyundeng_huoquyanzhengma_shuju)
            miyun_yanzhengma = (miyundeng_huoquyanzhengma_shuju['code'])
            yzm = 0
            while miyun_yanzhengma == "":
                time.sleep(5)
                miyundeng_huoquyanzhengma = requests.get(
                    "http://api.miyun.pro/api/get_message?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
                    verify=False)
                miyundeng_huoquyanzhengma_shuju = miyundeng_huoquyanzhengma.text
                miyundeng_huoquyanzhengma_shuju = json.loads(miyundeng_huoquyanzhengma_shuju)
                miyun_yanzhengma = (miyundeng_huoquyanzhengma_shuju['code'])
                if miyun_yanzhengma != "":
                    driver.find_element_by_id("validateCode").send_keys(miyun_yanzhengma)
                    print("获取的验证码:" + miyun_yanzhengma)
                    yzm = 0
                    break
                else:
                    yzm = yzm + 1
                    print("正在获取" + str(yzm) + "次验证码,每5秒获取1次,共获取30次")
                if yzm == 30:
                    # 拉黑
                    miyun_lahei = requests.get(
                        "http://api.miyun.pro/api/add_blacklist?token=" + miyun_token + "&project_id=55964&phone_num=" + miyun_shoujihao,
                        verify=False)
                    miyun_lahei_shuju = miyun_lahei.text
                    miyun_lahei_shuju = json.loads(miyun_lahei_shuju)
                    miyun_lahei_fanhui = miyun_lahei_shuju['message']
                    if miyun_lahei_fanhui == "ok":
                        print(miyun_shoujihao + "避免再次获取已拉黑")
                        miyun_shoujihao = ""
                        miyun_yanzhengma = ""
                    driver.refresh()
                    time.sleep(3)
                    # 获取手机号
                    miyundeng_huoqushoujihao = requests.get(
                        "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                    miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                    miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                    miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                    while miyun_shoujihao != "":
                        print("获取的手机号:" + miyun_shoujihao)
                        break
                    else:
                        miyundeng_huoqushoujihao = requests.get(
                            "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                        miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                        miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                        miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                    # 输入手机号
                    driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
                    time.sleep(1)
                    # 点击注册地
                    driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
                    # driver.find_element_by_class_name("van-field__right-icon").click()
                    time.sleep(1)
                    # 选择省份
                    driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
                    # driver.find_elements_by_class_name("van-cascader__option")[7].click()
                    # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
                    # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
                    time.sleep(1)
                    # 选择市
                    driver.find_elements_by_class_name("van-cascader__option")[17].click()
                    # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
                    time.sleep(1)
                    # 点击获取验证码按钮
                    driver.find_element_by_class_name("van-field__button").click()
                    time.sleep(1)
                    # 下一步内容
                    # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
                    ##按照页面进行元素定位
                    element = driver.find_element_by_class_name("verify-img-panel")
                    ##获取你的坐标{X,Y}
                    location = element.location
                    ##获取高度跟宽度
                    size = element.size

                    ##保存整个页面的截图
                    png = driver.get_screenshot_as_png()

                    ##使用PIL库在内存中打开图像
                    im = Image.open(BytesIO(png))

                    ##根据实际情况进行算法
                    left = location['x']
                    top = location['y']
                    right = location['x'] + size['width']
                    bottom = location['y'] + size['height']

                    im = im.crop((left, top, right, bottom))
                    ##截图
                    im.save('yanzhengma.png')
                    driver.switch_to.default_content()
                    time.sleep(1)
                    jiemajisuan()
                    time.sleep(1)

                    huakuai = driver.find_element_by_class_name("verify-move-block")

                    ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                    # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                    for x in get_track(QJ.quekouXzuobiaozhi - 25):
                        ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                    time.sleep(1)
                    ActionChains(driver).release().perform()

                    time.sleep(1)
                    yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                    while yanzhengmashifoucunzai == "向右滑动完成验证":
                        element = driver.find_element_by_class_name("verify-img-panel")
                        ##获取你的坐标{X,Y}
                        location = element.location
                        ##获取高度跟宽度
                        size = element.size

                        ##保存整个页面的截图
                        png = driver.get_screenshot_as_png()

                        ##使用PIL库在内存中打开图像
                        im = Image.open(BytesIO(png))

                        ##根据实际情况进行算法
                        left = location['x']
                        top = location['y']
                        right = location['x'] + size['width']
                        bottom = location['y'] + size['height']

                        im = im.crop((left, top, right, bottom))
                        ##截图
                        im.save('yanzhengma.png')
                        driver.switch_to.default_content()
                        time.sleep(1)
                        jiemajisuan()
                        time.sleep(1)

                        huakuai = driver.find_element_by_class_name("verify-move-block")

                        ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                        # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                        for x in get_track(QJ.quekouXzuobiaozhi - 25):
                            ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                        time.sleep(1)
                        ActionChains(driver).release().perform()

                        yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                        if yanzhengmashifoucunzai != "向右滑动完成验证":
                            break
                        time.sleep(3)

                    shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
                    while shoujihaoyizhuce == "此手机号已注册，请直接登录":
                        # 获取手机号
                        miyundeng_huoqushoujihao = requests.get(
                            "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964", verify=False)
                        miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                        miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                        miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                        while miyun_shoujihao != "":
                            print("获取的手机号:" + miyun_shoujihao)
                            break
                        else:
                            miyundeng_huoqushoujihao = requests.get(
                                "http://api.miyun.pro/api/get_mobile?token=" + miyun_token + "&project_id=55964",
                                verify=False)
                            miyundeng_huoqushoujihao_shuju = miyundeng_huoqushoujihao.text
                            miyundeng_huoqushoujihao_shuju = json.loads(miyundeng_huoqushoujihao_shuju)
                            miyun_shoujihao = (miyundeng_huoqushoujihao_shuju['mobile'])
                        # 输入手机号
                        driver.find_element_by_id("phoneNum").send_keys(miyun_shoujihao)
                        time.sleep(1)
                        # 点击注册地
                        driver.find_element_by_xpath("//input[@placeholder='注册城市请选择常住地，涉及会员权益']").click()
                        # driver.find_element_by_class_name("van-field__right-icon").click()
                        time.sleep(1)
                        # 选择省份
                        driver.find_element_by_xpath("//*[contains(text(),'湖北')]").click()
                        # driver.find_elements_by_class_name("van-cascader__option")[7].click()
                        # driver.find_element_by_xpath("//[text()='文字内容']").click()全部文字
                        # driver.find_element_by_xpath("//*[contains(text(),'文字内容')]").click() 部分文字
                        time.sleep(1)
                        # 选择市
                        driver.find_elements_by_class_name("van-cascader__option")[17].click()
                        # driver.find_element_by_xpath("//*[contains(text(),'武汉')]").click
                        time.sleep(1)
                        # 点击获取验证码按钮
                        driver.find_element_by_class_name("van-field__button").click()
                        time.sleep(1)
                        # 下一步内容
                        # 点击获取验证码后判断是否还是获取验证码，如果不是就可以继续注册
                        ##按照页面进行元素定位
                        element = driver.find_element_by_class_name("verify-img-panel")
                        ##获取你的坐标{X,Y}
                        location = element.location
                        ##获取高度跟宽度
                        size = element.size

                        ##保存整个页面的截图
                        png = driver.get_screenshot_as_png()

                        ##使用PIL库在内存中打开图像
                        im = Image.open(BytesIO(png))

                        ##根据实际情况进行算法
                        left = location['x']
                        top = location['y']
                        right = location['x'] + size['width']
                        bottom = location['y'] + size['height']

                        im = im.crop((left, top, right, bottom))
                        ##截图
                        im.save('yanzhengma.png')
                        driver.switch_to.default_content()
                        time.sleep(1)
                        jiemajisuan()
                        time.sleep(1)

                        huakuai = driver.find_element_by_class_name("verify-move-block")

                        ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                        # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                        for x in get_track(QJ.quekouXzuobiaozhi - 25):
                            ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                        time.sleep(1)
                        ActionChains(driver).release().perform()

                        time.sleep(1)
                        yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                        while yanzhengmashifoucunzai == "向右滑动完成验证":
                            element = driver.find_element_by_class_name("verify-img-panel")
                            ##获取你的坐标{X,Y}
                            location = element.location
                            ##获取高度跟宽度
                            size = element.size

                            ##保存整个页面的截图
                            png = driver.get_screenshot_as_png()

                            ##使用PIL库在内存中打开图像
                            im = Image.open(BytesIO(png))

                            ##根据实际情况进行算法
                            left = location['x']
                            top = location['y']
                            right = location['x'] + size['width']
                            bottom = location['y'] + size['height']

                            im = im.crop((left, top, right, bottom))
                            ##截图
                            im.save('yanzhengma.png')
                            driver.switch_to.default_content()
                            time.sleep(1)
                            jiemajisuan()
                            time.sleep(1)

                            huakuai = driver.find_element_by_class_name("verify-move-block")

                            ActionChains(driver).move_by_offset(25, 20).click_and_hold(huakuai).perform()
                            # ActionChains(driver).move_to_element_with_offset(huakuai, xoffset=QJ.quekouXzuobiaozhi, yoffset=0)
                            for x in get_track(QJ.quekouXzuobiaozhi - 25):
                                ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
                            time.sleep(1)
                            ActionChains(driver).release().perform()

                            yanzhengmashifoucunzai = driver.find_element_by_class_name("verify-bar-area").text
                            if yanzhengmashifoucunzai != "向右滑动完成验证":
                                break
                            time.sleep(3)

                        shoujihaoyizhuce = driver.find_element_by_class_name("van-toast__text").text
                        if shoujihaoyizhuce != "此手机号已注册，请直接登录":
                            break
                        time.sleep(3)

            time.sleep(3)
            xiayibuanniu = driver.find_element_by_class_name("van-button--large")
            panduanxiayibukefoudianji = xiayibuanniu.is_enabled()
            # 如果不能点击下一步拉黑号码并重新申请号码


        yanzhengmashurukuang = driver.find_element_by_id("validateCode")
        yanzhengmashurukuang_wenben = yanzhengmashurukuang.get_attribute('placeholder')
        print(yanzhengmashurukuang_wenben)
        while yanzhengmashurukuang_wenben != "请输入验证码":
            break
        else:
            yanzhengmashurukuang = driver.find_element_by_id("validateCode")
            yanzhengmashurukuang_wenben = yanzhengmashurukuang.get_attribute('placeholder')
            time.sleep(1)
        """

        # 点击同意按钮
        time.sleep(10)
        driver.switch_to.default_content()
        driver.find_element_by_css_selector("[class='van-button van-button--info van-button--normal']").click()

        # 点击个人资料
        time.sleep(10)
        driver.switch_to.default_content()
        driver.find_element_by_xpath("//*[contains(text(),'个人资料')]").click()

        # 点击完善/修改个人信息
        time.sleep(10)
        driver.switch_to.default_content()
        driver.find_element_by_xpath("//*[contains(text(),'完善/修改个人信息')]").click()

        # 点击退出当前账号
        time.sleep(10)
        driver.switch_to.default_content()
        driver.find_element_by_class_name("van-button--primary").click()

        baocunshoujihao = open(baocunlujing, "a+")
        baocunshoujihao.write(miyun_shoujihao + "\n")
        baocunshoujihao.close()
        print(miyun_shoujihao + "------注册完成------已保存"  + "\n")
        driver.quit()

        """
        # 定位起始元素
        source = driver.find_element_by_class_name("verify-move-block")
        # 让鼠标移动到起点元素上
        pyautogui.moveTo(source.location['x'] + 25, source.location['y'] + 150)
        # 定位要拖拽到的位置元素
        #target = driver.find_element_by_class_name("verify-move-block")
        # 实现拖拽功能
        pyautogui.dragTo(source.location['x'] + 25 + QJ.quekouxzuobiaozhi, source.location['y'] + 150, duration=5,button='left')
        #pyautogui.dragRel(target.location['x'] + 20, 0, duration=1,button='left')
        """

def b64_api(username, password, img_path, ID):
    with open(img_path, 'rb') as f:
        b64_data = base64.b64encode(f.read())
    b64 = b64_data.decode()
    data = {"username": username, "password": password, "ID": ID, "b64": b64, "version": "3.1.1"}
    data_json = json.dumps(data)
    result = json.loads(requests.post("http://www.tulingtech.xyz/tuling/predict", data=data_json).text)
    return result

def jiemajisuan():
    yanzhengmalujing = os.getcwd() + "\yanzhengma.png"
    img_path = yanzhengmalujing
    result = b64_api(username=QJ.tuling_zhanghao, password=QJ.tuling_mima, img_path=img_path, ID="78915616")
    print(result)
    fanhuizhi = result
    if fanhuizhi['code'] != 1:
        driver.quit()
        kaishizhuce()
    fanhuishuju = fanhuizhi['data']
    quekouzhi = fanhuishuju['缺口']
    QJ.quekouXzuobiaozhi = quekouzhi['X坐标值']

def get_track(distance):      # distance为传入的总距离
    # 移动轨迹
    track=[]
    # 当前位移
    current=0
    # 减速阈值
    mid=distance*4/5
    # 计算间隔
    t=0.2
    # 初速度
    v=1

    while current<distance:
        if current<mid:
            # 加速度为2
            a=2
        else:
            # 加速度为-2
            a=-4
        v0=v
        # 当前速度
        v=v0+a*t
        # 移动距离
        move=v0*t+1/2*a*t*t
        # 当前位移
        current+=move
        # 加入轨迹
        track.append(round(move))
    return track

def move_to_gap(slider, tracks):  # slider是要移动的滑块,tracks是要传入的移动轨迹
    ActionChains(driver).click_and_hold(slider).perform()
    for x in tracks:
        ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
    time.sleep(0.5)
    ActionChains(driver).release().perform()



kaishizhuce()